package com.jack.vipmis.vip.api.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jack.vipmis.common.web.controller.BaseController;
import com.jack.vipmis.vip.api.util.MsgUtil;
import com.jack.vipmis.vip.business.entity.Business;
import com.jack.vipmis.vip.business.service.BusinessService;

/**
 * 商家信息API
 * 
 * @author JackLiang
 * @version 1.0
 * @date 2014-6-30
 */
@Controller
@RequestMapping(value = "/api/business")
public class BusinessAPIController extends BaseController<Business, Long> {

	@Autowired
	private BusinessService	businessService;

	/**
	 * 通过ID查看商家信息
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "find")
	@ResponseBody
	public Map<String, Object> findBusinessById(@RequestParam("id") Long id) {
		try {
			Business bs = businessService.findOne(id);
			if (bs != null) {
				return MsgUtil.doneOk(bs);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return MsgUtil.doneFail();
	}

	/**
	 * 分页查询
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "findByPage", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> findByPage(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize,
			@RequestParam("sort") String sortType, @RequestParam("type") String type) {
		try {
			Page<Business> result = businessService.getBusinessByPage(page, pageSize, sortType, type);
			return MsgUtil.doneOk(result.getContent());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return MsgUtil.doneFail();
	}
}
